package com.taldh.netty.io.bio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author YuanDonghao
 */
public class BioServer {

    private int portNumber = 8080;

    public BioServer() {
    }

    public BioServer(int portNumber) {
        this.portNumber = portNumber;
    }

    public void start() throws IOException {
        ServerSocket serverSocket = new ServerSocket(portNumber);
        Socket clientSocket = serverSocket.accept();
        BufferedReader in = new BufferedReader(
                new InputStreamReader(clientSocket.getInputStream())
        );
        PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
        String request, response;

        while ((request = in.readLine()) != null) {
            if ("Done".equals(request)) {
                break;
            }
            response = "Tal test";
            out.println(response);
        }


    }

    public static void main(String[] args) throws IOException {
        new BioServer().start();
    }




}
